package com.yd.controller.yd;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yd.pojo.Kefus;
import com.yd.pojo.Merchants;
import com.yd.pojo.Sys;
import com.yd.pojo.Users;
import com.yd.service.KefusService;
import com.yd.service.MerchantsService;
import com.yd.service.SysService;
import com.yd.service.UsersService;
import com.yd.tool.UtsReg;


@Controller
public class UsersControllerYD {

	@Resource
	private UsersService usersService;
	@Resource
	private MerchantsService merchantsService;
	@Resource
	private KefusService kefusService;
	@Resource
	private SysService sysService;
	

	@RequestMapping(value={"/app/merchant/token/getuser"})
	@ResponseBody
	public String app_merchant_token(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String token = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getStringKB(request.getParameter("token"))){token = request.getParameter("token").trim();} else {jsonObject.put("msg","token错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Merchants merchants=merchantsService.selectOne(new EntityWrapper<Merchants>().eq("token", token));
		if(merchants==null){
			jsonObject.put("msg","token不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		merchants.setLoginpass("");

		jsonObject.put("data",merchants);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	
	@RequestMapping(value={"/app/user/token/getuser"})
	@ResponseBody
	public String app_user_token_getuser(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String token = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getStringKB(request.getParameter("token"))){token = request.getParameter("token").trim();} else {jsonObject.put("msg","token错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Users users=usersService.selectOne(new EntityWrapper<Users>().eq("token", token));
		if(users==null){
			jsonObject.put("msg","user不存在");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		jsonObject.put("data",users);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	
	@RequestMapping(value={"/app/kefu/token/getuser"})
	@ResponseBody
	public String app_kefu_token_getuser(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String token = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getStringKB(request.getParameter("token"))){token = request.getParameter("token").trim();} else {jsonObject.put("msg","token错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Kefus kefus=kefusService.selectOne(new EntityWrapper<Kefus>().eq("token", token));
		if(kefus==null){
			jsonObject.put("msg","user不存在");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		jsonObject.put("data",kefus);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	@RequestMapping(value={"/app/sys/token/getuser"})
	@ResponseBody
	public String app_sys_token_getuser(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String token = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getStringKB(request.getParameter("token"))){token = request.getParameter("token").trim();} else {jsonObject.put("msg","token错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Sys sys=sysService.selectOne(new EntityWrapper<Sys>().eq("token", token));
		if(sys==null){
			jsonObject.put("msg","管理员不存在");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		jsonObject.put("data",sys);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	@RequestMapping(value={"/app/user/id/getuser"})
	@ResponseBody
	public String app_user_id_getuser(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String id = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getIntXl(request.getParameter("id"))){id = request.getParameter("id").trim();} else {jsonObject.put("msg","id格式错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Merchants merchants=merchantsService.selectOne(new EntityWrapper<Merchants>().eq("id", id));
		if(merchants==null){
			jsonObject.put("msg","id不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		merchants.setLoginpass("");

		jsonObject.put("data",merchants);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	
	@RequestMapping(value={"/app/merchant/id/getuser"})
	@ResponseBody
	public String app_merchant_id_getuser(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String id = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getIntXl(request.getParameter("id"))){id = request.getParameter("id").trim();} else {jsonObject.put("msg","id格式错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Users users=usersService.selectOne(new EntityWrapper<Users>().eq("id", id));
		if(users==null){
			jsonObject.put("msg","user不存在");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		jsonObject.put("data",users);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
	
	@RequestMapping(value={"/app/kefu/id/getuser"})
	@ResponseBody
	public String app_kefu_id_getuser(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();

		String key = "";
		String id = "";
		if (UtsReg.getStringKB(request.getParameter("key"))){key = request.getParameter("key").trim();} else {jsonObject.put("msg","key错误");jsonObject.put("error", "1");return jsonObject.toString();}
		if (UtsReg.getStringKB(request.getParameter("id"))){id = request.getParameter("id").trim();} else {jsonObject.put("msg","id格式错误");jsonObject.put("error", "1");return jsonObject.toString();}
		
		if(!key.equals("yydd")){
			jsonObject.put("msg","key不正确");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		Kefus kefus=kefusService.selectOne(new EntityWrapper<Kefus>().eq("id", id));
		if(kefus==null){
			jsonObject.put("msg","user不存在");jsonObject.put("error", "1");return jsonObject.toString();
		}
		
		jsonObject.put("data",kefus);
		jsonObject.put("msg", "成功");
		jsonObject.put("error", "0");
		return jsonObject.toString();
	}
	
}



